import HttpRequestAPI from '@/services'
import type { Danmu, PaginationResultVO, VideoComment, VideoDanmuListVO } from '../video'
import type { VideoInfo } from '../home'

/**
 * 发布视频投稿Dto
 */
export interface PostVideoDto {
  videoId?: string
  videoCover: string
  videoName: string
  pcategoryId: number
  categoryId?: number
  postType: number
  tags: string
  introduction?: string
  interaction?: string
  uploadFileList: string
}

/**
 * 根据视频ID查询视频详情返回VO
 */
interface VideoInfoPost {
  videoId: string
  videoCover: string
  videoName: string
  userId: string
  createTime: string
  lastUpdateTime: string
  pCategoryId: number
  categoryId: number
  status: number
  postType: number
  originInfo: string
  tags: string
  introduction: string
  interaction: string
  duration: number
  statusName: string
}
interface VideoInfoFilePost {
  fileId: string
  uploadId: string
  userId: string
  videoId: string
  fileIndex: number
  fileName: string
  fileSize: number
  filePath: string
  updateType: number
  transferResult: number
  duration: number
}
interface VideoPostEditInfoVO {
  videoInfoPost: VideoInfoPost
  videoInfoFileList: VideoInfoFilePost[]
}

/**
 * 查询发布之后的稿件返回VO
 */
type VideoInfoPostPagination = PaginationResultVO<VideoInfoPost>

/**
 * 获取状态视频的数量
 */
interface VideoStatusCountInfoVo {
  auditPassCount: number
  auditFailCount: number
  inProgress: number
}

/**
 * 发布投稿视频
 * @returns string
 */
export const postVideoHttpRequest = (data: PostVideoDto) => {
  return HttpRequestAPI.post<null>({
    url: `/web/ucenter/postVideo`,
    data
  })
}

/**
 * 根据视频ID查询视频详情
 * @returns VideoPostEditInfoVO
 */
export const videoByVideoIdInfoHttpRequest = (videoId: string) => {
  return HttpRequestAPI.get<VideoPostEditInfoVO>({
    url: `/web/ucenter/getVideoByVideoId?videoId=${videoId}`
  })
}

/**
 * 查询发布之后的稿件
 * @returns VideoInfoPostPagination
 */
export const ucenterLoadVideoListHttpRequest = (params: {
  status: number
  pageNo: number
  pageSize?: number
  videoNameFuzzy: string
}) => {
  return HttpRequestAPI.get<VideoInfoPostPagination>({
    url: `/web/ucenter/loadVideoList`,
    params
  })
}

/**
 * 保存视频互动信息
 * @returns null
 */
export const saveVideoInteractionHttpRequest = (params: {
  interaction?: string
  videoId: string
}) => {
  return HttpRequestAPI.post<null>({
    url: `/web/ucenter/saveVideoInteraction`,
    params
  })
}

/**
 * 删除视频稿件信息
 * @returns null
 */
export const ucenterDeleteVideoHttpRequest = (params: { videoId: string }) => {
  return HttpRequestAPI.delete<null>({
    url: `/web/ucenter/deleteVideo`,
    params
  })
}

/**
 * 获取状态视频的数量
 * @returns VideoStatusCountInfoVo
 */
export const ucenterVideoStatusCountHttpRequest = () => {
  return HttpRequestAPI.get<VideoStatusCountInfoVo>({
    url: `/web/ucenter/getVideoStatusCount`
  })
}

/**
 * 加载所有视频信息(个人创作中心)
 * @returns VideoInfo[]
 */
export const loadAllVideoHttpRequest = () => {
  return HttpRequestAPI.get<VideoInfo[]>({
    url: `/web/ucenter/loadAllVideo`
  })
}

/**
 * 查询视频评论(个人创作中心)
 * @returns PaginationResultVO<VideoComment>
 */
export const ucenterLoadCommentHttpRequest = (videoId = '', pageNo = 0) => {
  return HttpRequestAPI.get<PaginationResultVO<VideoComment>>({
    url: `/interact/ucenter/loadComment`,
    params: {
      pageNo,
      videoId
    }
  })
}

/**
 * 查询视频弹幕(个人创作中心)
 * @returns PaginationResultVO<Danmu>
 */
export const ucenterLoadDanMuHttpRequest = (videoId = '', pageNo = 0) => {
  return HttpRequestAPI.get<PaginationResultVO<Danmu>>({
    url: `/interact/ucenter/loadDanMu`,
    params: {
      pageNo,
      videoId
    }
  })
}

/**
 * 删除评论 (个人创作中心)
 * @returns null
 */
export const ucenterDelCommentHttpRequest = (commentId: number) => {
  return HttpRequestAPI.delete<null>({
    url: `/interact/ucenter/deleteComment`,
    params: {
      commentId
    }
  })
}

/**
 * 删除弹幕 (个人创作中心)
 * @returns null
 */
export const ucenterDelDanMuHttpRequest = (danMuId: number) => {
  return HttpRequestAPI.delete<null>({
    url: `/interact/ucenter/deleteDanMu`,
    params: {
      danMuId
    }
  })
}
